<script type="text/javascript" src="../addons/ewei_shopv2/plugin/exchange/static/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="../addons/ewei_shopv2/plugin/exchange/static/css/bootstrap-multiselect.css" type="text/css"/>
<script type="text/javascript" src="../addons/ewei_shopv2/plugin/exchange/static/js/bootstrap-multiselect-collapsible-groups.js"></script>
<form {if $id>0}action="{php echo webUrl('exchange/group/edit',array('id'=>$id),true);}"{else}action="{php echo webUrl('exchange/group/add',array(),true);}"{/if} method="post" class="form-validate">

    <div class="modal-dialog" style="width: 750px">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-6 b-r" id="m">
                        <!--这里是商品选择器-->
                        <div id="goods">
                            <h3>请选择商品</h3>
                            <!--搜索条-->
                            <div class="modal-body" style="width: 80%;margin-left: 10%;">
                                <div class="row">
                                    <div class="input-group">
                                        <input type="text" class="form-control" name="keyword" id="goodsid_input" placeholder="请选择商品">
                                        <span class="input-group-btn">
                                            <button type="button" class="btn btn-default" onclick="biz.selector_new.search(this, 'goodsid');">搜索</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <ul id="myTab" class="nav nav-tabs">
                                <li class="active">
                                    <a href="#no" data-toggle="tab">
                                        无规格商品
                                    </a>
                                </li>
                                <li><a href="#has" data-toggle="tab">有规格商品</a></li>
                            </ul>
                            <div id="myTabContent" class="tab-content">
                                <div class="tab-pane fade in active" id="no">
                                    <div style="max-height:500px;overflow:auto;min-width:500px;">
                                        <table class="table">
                                            <thead>
                                            <tr>
                                                <td style="width: 250px">商品名称</td>
                                                <td style="width:150px;">商品规格</td>
                                                <td style="width:150px;">商品价格</td>
                                                <td style="width:150px;">参与兑换量:</td>
                                                <th>是否选择</th>
                                            </tr>
                                            </thead>
                                            <tbody class="ui-sortable">
                                            {loop $all $key $value}
                                            <tr>
                                                <td>
                                                    <img src="{$value['thumb']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc"> {$value['title']} </td>
                                                <td>{if $value['hasoption']==0}无规格{/if}{if $value['hasoption']==1}有规格{/if}</td>
                                                <td>¥{$value['marketprice']}</td>
                                                <td>
                                                    <a href="javascript:;" data-toggle="ajaxEdit" data-href="{php echo webUrl('exchange/goods/stock',array('goodsid'=>$value['id']));}" style="display: inline;">{$value['exchange_stock']}</a>
                                                </td>
                                                <td>
                                                    <div class="onoffswitch">
                                                        <input type="checkbox" name="no_checkbox[]" class="onoffswitch-checkbox" id="no{$value['id']}" value="{$value['id']}">
                                                        <label class="onoffswitch-label" for="no{$value['id']}">
                                                            <span class="onoffswitch-inner"></span>
                                                            <span class="onoffswitch-switch"></span>
                                                        </label>
                                                    </div>
                                                </td>
                                            </tr>
                                            {/loop}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="has">
                                    <div style="max-height:500px;overflow:auto;min-width:500px;">
                                        <table class="table">
                                            <thead>
                                            <tr>
                                                <td style="width: 250px">所属商品</td>
                                                <td style="width:150px;">商品规格</td>
                                                <td style="width:150px;">规格价格</td>
                                                <td style="width:150px;">参与兑换量:</td>
                                                <th>是否选择</th>
                                            </tr>
                                            </thead>
                                            <tbody id="param-items" class="ui-sortable">
                                            {php $i = 0;}
                                            {loop $option $p}
                                            {loop $option[$i] $key $value}
                                            {php $j = sizeof($option[$i])-1;}
                                            <tr>
                                                <td>
                                                    <img src="{$option[$i][0]['pic']}" style="width:30px;height:30px;padding1px;border:1px solid #ccc">{$option[$i][0]['gt']}</td>
                                                <td> {$value['title']}</td>
                                                <td>¥{$value['marketprice']}</td>
                                                <td>
                                                    <a href="javascript:;" data-toggle="ajaxEdit" data-href="{php echo webUrl('exchange/goods/stock',array('optionid'=>$value['id']));}" style="display: inline;">{$value['exchange_stock']}</a>
                                                </td>
                                                <td>
                                                    <div class="onoffswitch">
                                                        <input type="checkbox" name="has_checkbox[]" class="onoffswitch-checkbox" id="has{$value['id']}" value="{$value['id']}">
                                                        <label class="onoffswitch-label" for="has{$value['id']}">
                                                            <span class="onoffswitch-inner"></span>
                                                            <span class="onoffswitch-switch"></span>
                                                        </label>
                                                    </div>
                                                </td>
                                                <div id="new"></div><div id="old"></div>
                                            </tr>
                                            {php if($key>=$j)$i++;}
                                            {/loop}
                                            {/loop}

                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <span class="btn btn-primary btn-outline" onclick="$('#goods').hide();$('#edit').show();$('#m').removeClass().addClass('col-sm-6 b-r');$('#edit').show();$('#n').show();$('.modal-dialog').css('width','750px');">
                                选好了
                            </span>
                        </div>

                        <!--这里是编辑-->
                        <div id="edit">
                            <h3>{if $id>0}编辑组合兑换任务{else}添加组合兑换任务{/if}</h3>
                            <label>兑换组标题：</label>
                            <input type="text" placeholder="请输入标题" class="form-control" name="title" value="{$setting['title']}" required>
                            <br>
                            <label>开始时间：</label>
                            {php echo tpl_form_field_date('starttime',$setting['starttime'],true);}
                            <br>
                            <label>截止时间：</label>
                            {php echo tpl_form_field_date('endtime',$setting['endtime'],true);}
                            <br>

                            <script>$('#goods').hide();</script>

                            <label>商品最大兑换数(单位:件):</label>
                            <input type="text" name="max" class="form-control" value="{if empty($setting['max'])}0{/if}{$setting['max']}">
                            <br>
                            <label>商品兑换模式:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="type" class="type" value="1" id="bdadd" onclick="$('#shangpinadd').show();$('#mianzhiadd').hide();" {if $setting['type']!=2}checked{/if}><label for="bdadd"> 按指定商品兑换</label>&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="type" class="type" value="2" id="adadd" onclick="$('#shangpinadd').hide();$('#mianzhiadd').show();" {if $setting['type']==2}checked{/if}><label for="adadd"> 按指定面值兑换</label>
                            <br><br>
                            <div id="shangpinadd"  {if $setting['type']==2}style="display: none"{/if}>
                            <label>请选择商品:</label>
                            <a onclick="$('#goods').show();$('#edit').hide();$('#n').hide();$('#m').removeClass().addClass('col-sm-12');$('.modal-dialog').css('width','900px');" class="form-control">点击选择商品</a>
                        </div>
                        <div id="mianzhiadd"  {if $setting['type']!=2}style="display: none"{/if}>

                        <label>请输入商品兑换面值(单位:元):</label>
                        <input type="input" class="form-control" name="value" value="{$setting['value']}">
                    </div></div></div>
                    <br>
                    <div class="col-sm-6" id="n">
                        <label>余额兑换模式:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="balancetype" class="type" value="1" id="balance1" onclick="$('#balance_rand').hide();$('#balance').show();"
                               {if $setting['balance_type']!=2}checked{/if}><label for="balance1"> 指定余额兑换</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="balancetype" class="type" value="2" id="balance2" onclick="$('#balance_rand').show();$('#balance').hide();"
                               {if $setting['balance_type']==2}checked{/if}><label for="balance2"> 随机余额兑换</label>
                        <br>
                    <div id="balance" {if $setting['balance_type']==2}style="display: none"{/if}>
                        <br>
                        <label>请输入余额面值(单位:元):</label>
                        <input type="input" class="form-control" name="balance" value="{$setting['balance']}">
                    </div>
                        <div id="balance_rand" {if $setting['balance_type']!=2}style="display: none"{/if}>
            <br>
                            <label>请输入随机余额范围(单位:元)：</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="balance_left" value="{$setting['balance_left']}">
                                <span class="input-group-btn"><span class="btn btn-default">至</span></span>
                                <input type="text" class="form-control" name="balance_right" value="{$setting['balance_right']}">
                            </div>
                        </div>
                    <br>
                        <label>红包兑换模式:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="redtype" class="type" value="1" id="red1" onclick="$('#red_rand').hide();$('#red').show();"
                               {if $setting['red_type']!=2}checked{/if}><label for="red1"> 指定红包兑换</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="redtype" class="type" value="2" id="red2" onclick="$('#red_rand').show();$('#red').hide();"
                               {if $setting['red_type']==2}checked{/if}><label for="red2"> 随机红包兑换</label>
                        <br>
                    <div id="red" {if $setting['red_type']==2}style="display: none"{/if}>
                        <br>
                        <label>请输入红包面值(单位:元):</label>
                        <input type="input" class="form-control" name="red" value="{$setting['red']}">
                    </div>
                        <div id="red_rand" {if $setting['red_type']!=2}style="display: none"{/if}>
    <br>
                            <label>请输入随机红包范围(单位:元)：</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="red_left" value="{$setting['red_left']}">
                                <span class="input-group-btn"><span class="btn btn-default">至</span></span>
                                <input type="text" class="form-control" name="red_right" value="{$setting['red_right']}">
                            </div>
                        </div>
                    <br>
                        <label>积分兑换模式:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="scoretype" class="type" value="1" id="score1" onclick="$('#score_rand').hide();$('#score').show();"
                               {if $setting['score_type']!=2}checked{/if}><label for="score1"> 指定积分兑换</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="scoretype" class="type" value="2" id="score2" onclick="$('#score_rand').show();$('#score').hide();"
                               {if $setting['score_type']==2}checked{/if}><label for="score2"> 随机积分兑换</label>
                        <br>
                    <div id="score" {if $setting['score_type']==2}style="display: none"{/if}>
    <br>
                        <label>请输入积分数量(单位:个):</label>
                        <input type="input" class="form-control" name="score" value="{$setting['score']}" placeholder="0">
                    </div>
                        <div id="score_rand" {if $setting['score_type']!=2}style="display: none"{/if}>
    <br>
                            <label>请输入随机积分范围(单位:个)：</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="score_left" value="{$setting['score_left']}">
                                <span class="input-group-btn"><span class="btn btn-default">至</span></span>
                                <input type="text" class="form-control" name="score_right" value="{$setting['score_right']}">
                            </div>
                        </div>

                        <br>
                    <div id="coupon">
                        <label>选择优惠券：</label><br>
                        <script type="text/javascript">
                            $(document).ready(function() {
                                $('#example').multiselect({
                                    nonSelectedText: '未选择优惠券',
                                    allSelectedText: "全选",
                                    nSelectedText: '个优惠券已选',
                                    selectedList:10,
                                    buttonWidth: '100%',
                                    maxHeight: 200,
                                    enableCollapsibleOptGroups: true
                                });
                            });
                            $(function () {
                                $(".multiselect-container").css('width','100%');
                                $('.checkbox').css('color','#000');
                                $('.checkbox').css('background-color','#fff');
                            });
                        </script>

                        <select id="example" multiple="multiple" name="coupon[]">
                            {loop $category $k $v}
                            <optgroup label="{$v['name']}">
                                {loop $coupon[$k] $x $y}
                                <option value="{$y['id']}">{$y['couponname']}</option>
                                {/loop}
                            </optgroup>
                            {/loop}
                        </select>


                </div>
                    </div>
            </div>
        <div style="text-align: center;margin-top: 30px">
            <button type="submit" class="btn btn-primary">
                {if $id>0}保存{else}添加{/if}
            </button>
            <button type="button" class="btn btn-primary btn-outline" data-dismiss="modal">
                取消
            </button>
        </div>
        </div>
    </div>
    </div>
    </div>
</form>
